package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.SysPermMapper;
import org.linlinjava.litemall.db.domain.SysPerm;
import org.linlinjava.litemall.db.domain.SysPermExample;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zhy
 * @create 2018-10-08 10:50
 **/
@Service
public class LitemallSysPermService {
	@Resource
	private SysPermMapper sysPermMapper;

	public List<SysPerm> getList(Integer ptype){
		SysPermExample example = new SysPermExample();
        SysPermExample.Criteria criteria=example.createCriteria();
		if(!StringUtils.isEmpty(ptype)){
			criteria.andPtypeEqualTo(ptype);
		}
		return sysPermMapper.selectByExample(example);
	}

	public void deleteByptype(Integer ptype){
		sysPermMapper.deleteByptype(ptype);
	}

	public void saveOrUpdate(List<SysPerm> perms){
		if (perms!=null&&!perms.isEmpty()){
			sysPermMapper.saveOrUpdate(perms);
		}
	}

	public List<SysPerm> getPermsByRoleId(Integer roleId){
		return sysPermMapper.getPermsByRoleId(roleId);
	}

	public List<Map> getPermsByUserId(Integer userId){
		return sysPermMapper.getPermsByUserId(userId);
	}
}
